//--------------------------------------------------------------------------------------------------------------
// <copyright file="CSPStreetMap.cs" company="Microsoft Corporation" author="David Martos" date="01/02/2008">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//--------------------------------------------------------------------------------------------------------------
using System;
using System.Resources;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

using CSP.LoggingEngine;
using CSP.Core;

namespace CSP.WebParts
{
    /// <summary>
    /// This webpart shows a Virtual Earth map given a default latitude and longitude.
    /// </summary>
    [Guid("94008F15-5A4B-4110-B60C-8CA7DF6E4EBE")]
    public class CSPStreetMap : BaseWebPart
    {
        #region WebPart Properties

        /// <summary>
        /// Latitude of the default map shown by the webpart
        /// </summary>
        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [ResourcesAttribute("DefaultLatitudeDisplayName", "CSPWebPartParameterCategory", "DefaultLatitudeDescription")]
        public string DefaultLatitude
        {
            get { return this.defaultLatitude; }
            set { this.defaultLatitude = value; }
        }

        /// <summary>
        /// Longitude of the default map shown by the webpart
        /// </summary>
        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [ResourcesAttribute("DefaultLongitudeDisplayName", "CSPWebPartParameterCategory", "DefaultLongitudeDescription")]
        public string DefaultLongitude
        {
            get { return this.defaultLongitude; }
            set { this.defaultLongitude = value; }
        }

        #endregion

        private string defaultLatitude = "0.0";
        private string defaultLongitude = "0.0";
        /// <summary>
        /// Web user control which defines the output of the webpart
        /// </summary>
        protected UserControls.CSPStreetMapWUC control;
        #region WebPart Members

        

        #endregion

        #region Methods
        /// <summary>
        /// Constructor
        /// </summary>
        public CSPStreetMap()
        {
            this.ExportMode = WebPartExportMode.All;
        }

        /// <summary>
        /// When created, this webpart loads its web user control and sets its public variables
        /// </summary>
        protected override void CreateChildControls()
        {
            try
            {
                base.CreateChildControls();

                control = (UserControls.CSPStreetMapWUC)this.Page.LoadControl(WebPartConstants.CSPStreetMapWUCLocation);
                control.WrapperWebPart = this;

                control.DefaultLatitude = this.defaultLatitude;
                control.DefaultLongitude = this.defaultLongitude;

                this.Controls.Add(control);
            }
            catch (CSPException cspex)
            {
                errors.Add(this.LoadResource(WebPartConstants.CSPGenericErrorMessage));
            }
            catch (Exception ex)
            {
                LogMessage(WebPartConstants.CSPProceduresLoadErrorMessage, this.GetType().Name, ex);
                errors.Add(this.LoadResource(WebPartConstants.CSPGenericErrorMessage));
            }
        }
        #endregion
    }
}
